package yws.ssm.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import yws.ssm.domain.Account;
import yws.ssm.service.AccountService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 账户web
 */
@Controller
@RequestMapping("/account")
public class AccountController {

    @Autowired
    private AccountService accountService;

    @RequestMapping("/testfindall")
    public String testfindall(Model model){
        System.out.println("表现层：查询所有帐户...");
        //调用service的方法，就意味着spring整合了springmvc
        List<Account> list=accountService.find_all();
        model.addAttribute("list",list);
        return "list";
    }
    @RequestMapping("/save")
    public String save(Account account, HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("表现层：查询所有帐户...");
        accountService.saveAccount(account);
        response.sendRedirect(request.getContextPath()+"/account/testfindall");
        return "list";
    }
}
